﻿using Application.ProductUnitService;
using Domain.Entity.bs;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WMSManage.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]//需要鉴权
    public class ProductUnitController : ControllerBase
    {
        private readonly IProductUnitService productUnitService;

        public ProductUnitController(IProductUnitService productUnitService)
        {
            this.productUnitService = productUnitService;
        }


        /// <summary>
        /// 添加辅助单位
        /// </summary>
        /// <param name="procid">货品id</param>
        /// <param name="unit">单位</param>
        /// <param name="barcode">条码</param>
        /// <param name="num">数量</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddUnit(int procid, string unit, string barcode, int num)
        {
            return await productUnitService.AddUnit(procid, unit, barcode, num);
        }


        /// <summary>
        /// 根据货品id查询辅助单位
        /// </summary>
        /// <param name="procid">货品id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<ProductUnit>> GetUnitByPid(int procid)
        {
            return await productUnitService.GetUnitByPid(procid);
        }


        /// <summary>
        /// 修改辅助单位(先删除再添加)
        /// </summary>
        /// <param name="procid">货品id</param>
        /// <param name="unit">单位</param>
        /// <param name="barcode">条码</param>
        /// <param name="num">数量</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateUnit(int procid, string unit, string barcode, int num)
        {
            return await productUnitService.UpdateUnit(procid,unit, barcode, num);
        }
    }
}
